import cv2
import numpy as np



# 加载图像区块数据
def loadingImage(folder, zoom, xy, code = ".png"):
    imgs = []
    names = []
    for i in range(0, len(xy)):
        row_img = []
        name = []
        for j in range(0, len(xy[i])):
            s_location = folder + "/" + str(zoom) + "/" + str(xy[i][j][0]) + "/" + str(xy[i][j][1]) + code
            # print(s_location)
            img = cv2.imread(s_location)
            row_img.append(img)
            name.append(s_location)
            # cv2.imshow("imgs", img)
            # cv2.waitKey(300)
        imgs.append(row_img)
        names.append(name)
    return imgs, names



# 对图像进行拼接
def merge_images(imgs, names):
    row = len(imgs)
    col = len(imgs[0])
    # print("row = ", row)
    # print("col = ", col)
    # 新建画布
    image_ret = np.zeros((row * 256, col * 256, 3), np.uint8)  

    for i in range(0, row):
        for j in range(0, col):
            # print(i, j)
            image_ret[j*256:(j+1)*256, i*256:(i+1)*256] = imgs[i][j]
            # print(names[i][j])
    return image_ret
    